package com.dao;

import java.util.List;
import com.hbt.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import com.bean.Venta;


public class VentaDAO {
	
	
	private static SessionFactory sf = null;
	private static VentaDAO instancia = null;
	
	public static VentaDAO getInstancia(){
		if(instancia == null){
			sf = HibernateUtil.getSessionFactory();
			instancia = new VentaDAO();
		}
		return instancia;
	}
	
	public void grabarVenta (Venta venta){
		Session session = sf.openSession();
		session.beginTransaction();
		session.persist(venta);
		session.flush();		
		session.getTransaction().commit();	
		session.close();
	}
	
	public Venta getVenta(Venta venta) {
		Session session = sf.openSession();
		Venta v = (Venta) session.get(Venta.class, venta.getId());
		session.close();
		return v;
	}
	
	public List<Venta> getVentas(){
		Session session = sf.openSession();
		List<Venta> resutl = session.createQuery("from Venta").list();
		session.close();
		return resutl;	
		
	}

}
